<?php
header("Cache-Control:no-cache, must-revalidate");  
?>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<table border="0">
<tr>
<td width="120px" height="80px"><b>图书条码</b></td>
<td><div class="input-group input-group-lg"><input type="text" class="form-control input-lg" style = "width:500px" id="bookCode">
	<input type="button"  class="btn btn-primary btn-lg" value="查找" id="search"></div></td>
</tr>
<tr>
<td width="120px" height="80px"><b>图书名称</b></td>
<td><input type="text" class="form-control input-lg" style = "width:500px" id="bookName"></td>
</tr>
<tr>
<td width="120px" height="80px"><b>作者</b></td>
<td><input type="text" class="form-control input-lg" style = "width:300px" id="bookAuthor"></td>
</tr>
<tr>
<td width="120px" height="80px"><b>数量</b></td>
<td><input type="text" class="form-control input-lg" style = "width:300px" id="bookQty"></td>
</tr>
<td width="120px" height="80px"><b>图书编号<span style="color: red">*</span></b></td>
<td><input type="text" class="form-control input-lg" style = "width:100px" id="bookID" disabled></td>
</tr>
<tr>
<td width="120px" height="80px"></td>
<td><input type="submit" class="btn btn-warning btn-lg" value="修改" id="alter"></td>
</tr>
</table>
</div>
<script>
$("#search").click(function(){
	var bookCode = $("#bookCode").val();
	if(!bookCode){
		alert("请将表单填写完整");
	}else{
		$.ajax({
			type: "POST",
			url: "../../controller/searchController.php",
			data: {
				bookcode: bookCode
			},
			success: function(data){
				if(data == "false"){
					alert("没有找到该本书 :(");
				}else{
					ajaxobj = eval("("+data+")");

					$("#bookName").val(ajaxobj.name);
					$("#bookAuthor").val(ajaxobj.author);
					$("#bookQty").val(ajaxobj.qty);
					$("#bookID").val(ajaxobj.id);
				}
			}
		})
	}
})

$("#alter").click(function(){
	var bookCode = $("#bookCode").val();
	var bookName = $("#bookName").val();
	var bookAuthor = $("#bookAuthor").val();
	var bookQty = $("#bookQty").val();
	var bookID = $("#bookID").val();

	// var bookObj = {
	// 	'code': bookCode,
	// 	'name': bookName,
	// 	'author': bookAuthor,
	// 	'qty': bookQty
	// };
	if($("#bookID").val()){
		$.ajax({
			type: "POST",
			url: "../../controller/alterController.php",
			data: {
				bookcode: bookCode,
				bookname: bookName,
				bookauthor: bookAuthor,
				bookqty: bookQty,
				bookid: bookID
			},
			success: function(data){
				alert(data);
				$("#bookCode").val("");
				$("#bookName").val("");
				$("#bookAuthor").val("");
				$("#bookQty").val("");
				$("#bookID").val("");
			}
		});
	}else{
		alert("请先查找图书 :)");
	}


})
</script>
